<div class="da-list-wrap">
  <div class="da-content-banner">
    <d-breadcrumb>
      <d-breadcrumb-item><a routerLink="/">{{ 'basicdata.breadcrumb.home' | translate }}</a></d-breadcrumb-item>
      <d-breadcrumb-item><a routerLink="/pages/purchase/purchase-order">采购订单</a></d-breadcrumb-item>
      <d-breadcrumb-item>采购订单—维护</d-breadcrumb-item>
    </d-breadcrumb>
  </div>
  <div class="da-content-wrapper">
    <div class="da-form-container">
      <div class="card">
        <form dForm ngForm [layout]="layoutDirection" [labelSize]="'sm'" [labelAlign]="'end'" class="mt-5"
          (dSubmit)="submit($event)">
          <div class="form-header">
            <p class="form-title">采购订单—维护</p>
            <div class="form-head-btnGroup">
              <d-form-operation class="form-header-btn">
                <d-button class="me-3" bsStyle="primary" (btnClick)="selectRequirement()">选源单</d-button>
                <d-button class="me-3" bsStyle="primary" dFormSubmit>确定</d-button>
                <d-button class="me-3" bsStyle="primary" dFormSubmit (btnClick)="isStartApprovalChange()">确定并发起审核</d-button>
                <d-button bsStyle="common" (btnClick)="cancel()">取消</d-button>
              </d-form-operation>
            </div>
          </div>
          <div class="form-body">
            <div>
              <h4>基础信息</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>采购订单号</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="采购订单号" [(ngModel)]="purchaseOrder.purchaseOrderNum"
                      [dValidateRules]="purchaseOrderRules.purchaseOrderNum">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>单据日期</span>
                  </d-form-label>
                  <d-form-control>
                    <d-datepicker-pro name="单据日期" [appendToBody]="true" [(ngModel)]="purchaseOrder.orderDate"
                      [dValidateRules]="purchaseOrderRules.advicePurchaseDate">
                    </d-datepicker-pro>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>供应商</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="供应商" [(ngModel)]="purchaseOrder.supplyChineseName"
                      [dValidateRules]="purchaseOrderRules.supplyChineseName" readonly (click)="selectSupply()">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">供应商简称</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="供应商简称" [(ngModel)]="purchaseOrder.supplyShortName"
                      [dValidateRules]="purchaseOrderRules.supplyShortName" disabled="true">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">供应商英文名称</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="供应商英文名称" [(ngModel)]="purchaseOrder.supplyEnglishName"
                      [dValidateRules]="purchaseOrderRules.supplyEnglishName" disabled="true">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">供应商联系人</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select [placeholder]="'供应商联系人'" [options]="supplyContactOption" size="sm" name="供应商联系人"
                      [(ngModel)]="supplyContact" [filterKey]="'supplyContactName'"
                      (ngModelChange)="selectSupplyContact($event)"></d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>收货地址</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="收货地址" [(ngModel)]="purchaseOrder.address"
                      [dValidateRules]="purchaseOrderRules.address">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">业务员</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="业务员" [(ngModel)]="purchaseOrder.purchaseManName" readonly
                      (click)="selectUser()" [dValidateRules]="purchaseOrderRules.purchaseManName">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">部门</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="部门" [(ngModel)]="purchaseOrder.departmentName" readonly
                      (click)="selectDepartment()">
                  </d-form-control>
                </d-form-item>
              </div>
              <!-- <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">交易币种</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select [placeholder]="'交易币种'" [options]="currencyOption" size="sm" name="交易币种"
                      [(ngModel)]="currency" [filterKey]="'currencyName'"
                      (ngModelChange)="selectcurrency($event)"></d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">结算方式</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select [placeholder]="'结算方式'" [options]="settlementMethodOption" size="sm" name="结算方式"
                      [(ngModel)]="settlementMethod" [filterKey]="'settlementMethodName'"
                      (ngModelChange)="selectsettlementMethodOption($event)"></d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">付款账期</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select [placeholder]="'付款账期'" [options]="collectionPeriodOption" size="sm" name="付款账期"
                      [(ngModel)]="collectionPeriod" [filterKey]="'collectionPeriodName'"
                      (ngModelChange)="selectcollectionPeriodOption($event)"></d-select>
                  </d-form-control>
                </d-form-item>
              </div> -->
              <div class="u-1">
                <d-form-item>
                  <d-form-label>
                    <span class="label">备注</span>
                  </d-form-label>
                  <d-form-control class="textarea">
                    <textarea dTextarea name="备注" [(ngModel)]="purchaseOrder.remark"></textarea>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
            <div>
              <h4>物料信息</h4>
            </div>
            <div class="table">
              <d-data-table [dataSource]="purchaseOrder.purchaseOrderParts" [lazy]="true" [scrollable]="true"
                [fixHeader]="true" [scrollable]="true" [resizeable]="true" [tableWidthConfig]="tableWidthConfig">
                <thead dTableHead>
                  <tr dTableRow>
                    <th dHeadCell [fixedLeft]="'0px'">
                      <span>操作</span>
                    </th>
                    <th dHeadCell>
                      <span><span class="Required">*</span>物料编码</span>
                    </th>
                    <th dHeadCell>
                      <span>图片</span>
                    </th>
                    <th dHeadCell>
                      <span>物料名称</span>
                    </th>
                    <th dHeadCell>
                      <span>物料规格</span>
                    </th>
                    <th dHeadCell>
                      <span>物料描述</span>
                    </th>
                    <th dHeadCell>
                      <span>单位</span>
                    </th>
                    <th dHeadCell>
                      <span>是否检验</span>
                    </th>
                    <th dHeadCell>
                      <span>实时库存</span>
                    </th>
                    <th dHeadCell>
                      <span><span class="Required">*</span>采购数量</span>
                    </th>
                    <th dHeadCell>
                      <span><span class="Required">*</span>预计到货日期</span>
                    </th>
                    <th dHeadCell>
                      <span>单价(含税)</span>
                    </th>
                    <th dHeadCell>
                      <span><span class="Required">*</span>税率(%)</span>
                    </th>
                    <th dHeadCell>
                      <span>不含税单价</span>
                    </th>
                    <th dHeadCell>
                      <span>含税金额</span>
                    </th>
                    <th dHeadCell>
                      <span>不含税金额</span>
                    </th>
                    <th dHeadCell>
                      <span>税额</span>
                    </th>
                    <th dHeadCell>
                      <span>来源单号</span>
                    </th>
                    <th dHeadCell>
                      <span>备注</span>
                    </th>

                  </tr>
                </thead>
                <tbody dTableBody>
                  <ng-template let-rowItem="rowItem" let-rowIndex="rowIndex">
                    <tr dTableRow>
                      <td dTableCell [fixedLeft]="'0px'">
                        <span (click)="addRow()"><i class="icon-code-editor-add add"></i></span>
                        <span class="ms-3" (click)="deleteRow(rowIndex)"><i class="icon-code-editor-less minus" style="font-size: 16px;"></i></span>
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.partNum" readonly (click)="selectMaterial(rowItem)" [dValidateRules]="{
                          messageShowType:'none',
                          validators: [
                            { required: true },
                          ]
                        }">
                      </td>
                      <td dTableCell>
                        <span>
                          <div dImagePreview>
                            <d-badge *ngIf="rowItem.image" [count]="getImagesArray(rowItem.image).length" status="success">
                              <ng-container *ngFor="let imageUrl of getImagesArray(rowItem.image); let i = index">
                                <img *ngIf="getImagesArray(rowItem.image).length > 0" [src]="imageUrl" alt="图片" width="30px" height="30px" [ngStyle]="{'display': i === 0 ? 'block' : 'none'}" />
                              </ng-container>
                            </d-badge>
                          </div>
                        </span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partName">{{rowItem.partName}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partType">{{rowItem.partType}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.description">{{rowItem.description}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partUOM">{{rowItem.partUOM}}</span>
                      </td>
                      <td dTableCell>
                        <d-select [ngModelOptions]="{standalone: true}" size="sm" [options]="options" [(ngModel)]="rowItem.isInspection" [appendToBody]="true" [filterKey]="'label'" [valueKey]="'value'"></d-select>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.realTimeInventory">{{rowItem.realTimeInventory}}</span>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [(ngModel)]="rowItem.purchaseQuantity" class="input-number" [ngModelOptions]="{standalone: true}" [dValidateRules]="purchaseOrderRules.purchaseQuantity" (afterValueChanged)="purchaseQuantityChange(rowItem, $event)"></d-input-number>
                      </td>
                      <td dTableCell>
                        <d-datepicker-pro [(ngModel)]="rowItem.estimatedDeliveryDate" [ngModelOptions]="{standalone: true}" [appendToBody]="true" [dValidateRules]="purchaseOrderRules.estimatedDeliveryDate"></d-datepicker-pro>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [(ngModel)]="rowItem.priceWithTax" class="input-number" [ngModelOptions]="{standalone: true}" [dValidateRules]="purchaseOrderRules.priceWithTax" (afterValueChanged)="priceWithTaxChange(rowItem, $event)"></d-input-number>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [ngModel]="Math.floor(rowItem.taxRate * 100)" class="input-number" [ngModelOptions]="{standalone: true}" (afterValueChanged)="taxRateChange(rowItem, $event)"></d-input-number>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.priceWithoutTax">{{rowItem.priceWithoutTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.amountWithTax">{{rowItem.amountWithTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.amountWithoutTax">{{rowItem.amountWithoutTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.taxAmount">{{rowItem.taxAmount}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.purchasereQuireNum">{{rowItem.purchasereQuireNum}}</span>
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.note">
                      </td>
                    </tr>
                  </ng-template>
                </tbody>
              </d-data-table>
            </div>
            <div class="mt-5">
              <h4>费用及收款</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">数量合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="数量合计"
                      [(ngModel)]="purchaseOrder.totalPurchaseQuantity" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">金额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="金额合计（含税）"
                      [(ngModel)]="purchaseOrder.totalaMountWithTax" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">不含税金额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="不含税金额合计"
                      [(ngModel)]="purchaseOrder.totalAmountWithoutTax" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">税额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="税额合计" [(ngModel)]="purchaseOrder.totalTaxAmount"
                      disabled>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
            <div class="mt-20">
              <h4>其他</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">附件</span>
                  </d-form-label>
                  <d-form-control>
                    <d-badge [count]="fujianNumber">
                      <d-button bsStyle="common" (btnClick)="fujian()"><i
                          class="icon icon-upload me-2"></i><span>附件</span></d-button>
                    </d-badge>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
          </div>
          <d-form-operation class="form-footer">
            制单人：{{purchaseOrder.creator}}
          </d-form-operation>
        </form>
      </div>
    </div>

  </div>
</div>

<d-toast [value]="msgs" [life]="2000" [styleClass]="'custom-class'" [style]="{ left: '50%',top:'10px' }"></d-toast>
